Shinylive test

Author

김세창(교육종합연구원, 사회교육과 지리전공 석사)

Shinylive

Shinylive는 서버 없이 정적 웹페이지에서 Shiny를 작동하게끔 만들어주는 WASM 패키지이다. 여기서는 대륙을 선택하면, 해당 대륙 내 국가들의 TFR만 그려주는 간단한 웹 애플리케이션을 shinylive를 통해 구현해본다. 과연 될까??2

library(readr)
path <- file.path("data", "wpp_2022.rds")
data <- read_rds(path)

DT::datatable(data)
Warning in instance$preRenderHook(instance): It seems your data is too big for
client-side DataTables. You may consider server-side processing:
https://rstudio.github.io/DT/server.html
#| standalone: true
#| viewerHeight: 800
library(ggplot2)
library(dplyr)
library(shiny)

# Define your ui and server code here
ui <- fluidPage(
  titlePanel("World Population Prospects"),
  
  sidebarLayout(
    sidebarPanel(
      selectInput("country", "Select a country:",
                  choices = unique(data$ISO3),
                  selected = "KOR")
    ),
    
    mainPanel(
      plotOutput("popTrend")
    )
  )
)


# Define server logic
server <- function(input, output) {
  
  # Filter data based on selected continent
  countryData <- reactive({
    data |> 
      filter(ISO3 == input$country)
  })
  
  
  # Generate the map output
  output$popTrend <- renderPlot({
    ggplot(data = countryData(), aes(x=year, y=pop_jan_total)) +
      geom_line()
  })
}

# Run the application 
shinyApp(ui = ui, server = server)